package cn.kgc.vue.service.impl;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.common.ResponseStatus;
import cn.kgc.vue.form.ScheduleLsitForm;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.Schedule;
import cn.kgc.vue.service.ScheduleService;
import cn.kgc.vue.mapper.ScheduleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author
 * @description 针对表【schedule】的数据库操作Service实现
 * @createDate 2023-08-20 18:34:29
 */
@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule>
        implements ScheduleService {
    @Autowired
    private ScheduleMapper scheduleMapper;

    @Override
    public ResponseResult getlist(ScheduleLsitForm scheduleLsitForm) {
        ResponseResult responseResult = new ResponseResult();
        Page<Schedule> page = new Page<>(scheduleLsitForm.getPage(), scheduleLsitForm.getLimit());
        LambdaQueryWrapper<Schedule> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(scheduleLsitForm.getPrincipal()),Schedule::getPrincipal,scheduleLsitForm.getPrincipal())
                .eq(StringUtils.isNotEmpty(scheduleLsitForm.getLecturer()),Schedule::getLecturer,scheduleLsitForm.getLecturer());
        Page<Schedule> schedulePage = scheduleMapper.selectPage(page, wrapper);
        List<Schedule> records = schedulePage.getRecords();
        long total = schedulePage.getTotal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("schedule",records);
        responseResult.success(ResponseStatus.SUCCESS,map);
        return responseResult;
    }
}




